if(!CLIENT) then return end
local Player = LocalPlayer()
local Panel = false
local MainUserMessage = ""

local UserlistCSS = [[<style type="text/css"><!--
body {
	background-image: url(http://www.garrysmod.com/img/stripe.png);
}
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	color: #FFFFFF;
	font-weight: bold;
	background-color: #0066FF;
}
.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px
}
-->
</style>]]

local function AddItem(Name, OptionText, OverrideName)
	OptionText = OptionText || ""
	local Panel = vgui.Create("Panel", PanelList)
	local Label = vgui.Create("Label", Panel)
	Label:SetText(Name..OptionText)
	if(OverrideName) then Label:SetText(OverrideName..OptionText) end
	Label:SetPos(0, 0)
	Label:SetSize(200, 50)
	local Control = vgui.Create(Name, Panel)
	Control:SetPos(200, 15)
	Panel:SetTall(50)	
	return Panel, Control
end

local function OpenUserlist()
	local Width = 450
	local Height = 450
	
	local Window = vgui.Create("DFrame")
	Window:SetSize(Width, Height)
	Window:Center()
	Window:SetTitle("Derma Initiative Tests")
	Window:SetVisible(true)
	Window:MakePopup()
	
	local PanelList = vgui.Create("DPanelList", Window)
	PanelList:EnableVerticalScrollbar()
	PanelList:EnableHorizontal(false)
	PanelList:SetSize(Width - 20, Height - 20)
	PanelList:SetPos(300, 150)
	
	local PanelHTML, Control = vgui.Create("HTML", Window)
	Control:SetHTML("<html>"..UserlistCSS.."<body><table border=\"1\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>"..self.Users.."</td></tr></table></body></html>")
	Control:SetSize(Width - 25, Height - 25)
	PanelList:AddItem(PanelHTML)
	
	local Panel, Control = AddItem("DButton")
	Control:SetText("Refresh")
	Control:SetSize(150, 20)
	Control.DoClick = function (btn) Player:ConCommand("Userlist\n") end
	PanelList:AddItem(Panel)
	
	PanelList:PerformLayout()
end

function UserListCheckHook(um)
	local AddedUserMessage = um:ReadString()
	if(AddedUserMessage == "</table>") then
		MainUserMessage = MainUserMessage..AddedUserMessage
		Player:SetNetworkedString("UserList", MainUserMessage)
		MainUserMessage = ""
		OpenUserlist()
	else
		MainUserMessage = MainUserMessage..AddedUserMessage
	end
end
usermessage.Hook("UserListCheck", UserListCheckHook) 


	